//
//  SAPlayAppManager.m
//  GameFrame
//
//  Created by Hiroshi Nomura on 2014/05/24.
//  Copyright (c) 2014年 Hiroshi Nomura. All rights reserved.
//

#import "SAPlayAppManager.h"

#import "SAAppStageConfig.h"
#import "SARenderer.h"
#import "SAEventManager.h"

@interface SAPlayAppManager()

@property (nonatomic, retain) SAAppStageConfig* stageConfig;
@property (nonatomic, retain) SAEventManager* eventManager;

@property (nonatomic, retain) NSMutableDictionary* renderDict;

@end


@implementation SAPlayAppManager

@synthesize stageConfig, eventManager, renderDict;

@synthesize status;

-(void)setupApp:(NSString *)stageName
{
    //Load stage configuration file
    self.stageConfig = [[SAAppStageConfig alloc] initWihStage:stageName];
    
    //Create Normal Renderer
    EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
    if (context == nil)
    {
        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    }
    [EAGLContext setCurrentContext:context];
    
    
    self.renderDict = [[NSMutableDictionary alloc] init];
    SARenderer* defaultRenderer = [[SARenderer alloc] initWithContext:context andDrawable:nil];
    [self.renderDict setValue:defaultRenderer forKey:self.stageConfig.defaultRenderName];
    
    //TODO: Load extra render
    for (NSString* key in self.stageConfig.renderNameDict)
    {
        NSString* renderName = (NSString*)[self.stageConfig.renderNameDict objectForKey: key];
    }
    
}

-(void)start
{
    
}

-(void)render
{

}

-(void)update
{
    [self processConsoleEvent];
}

-(void)restart
{
    
}

-(void)suspend
{
    
}

-(void)resume
{
    
}

-(void)exit
{
    
}

-(void)handleConsoleEvent:(SAPlayViewController*)controller
{
    
}

-(void)processConsoleEvent
{
    
}

@end
